import java.io.*;
import java.util.*;
import java.util.Scanner;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

public class Access extends JPanel
{
	private JPanel accessP;
	private JLabel pwString;
	private JPasswordField pwTF;
	private JButton sign;

	private boolean getAccessed = false;

	
	
	public Access ()
	{
		setBackground (Color.white);
		setLayout (new BoxLayout(this, BoxLayout.Y_AXIS));


		accessP = new JPanel ();
			accessP.setBackground (Color.white);

		pwString = new JLabel ("PW : ");
		pwTF = new JPasswordField (8);
			pwTF.setBackground (new Color (252,245,245));
			pwTF.setEchoChar ('*');

		sign = new JButton (" Sing In ");
			sign.setBackground (Color.white);
			sign.setBorder (BorderFactory.createLineBorder (new Color (255, 238, 238), 4));
			sign.addActionListener (new EventsListener());

		accessP.add (pwString);
		accessP.add (pwTF);
		accessP.add (sign);



		add (Box.createRigidArea (new Dimension (0,185)));
		add (Box.createVerticalGlue()); 
		add (accessP);
		add (Box.createRigidArea (new Dimension (0,195)));
		add (Box.createVerticalGlue());
	}



	private class EventsListener implements ActionListener
	{
		public void actionPerformed (ActionEvent event)
		{
			if (event.getSource() == sign)
			{
				String enteredPW = pwTF.getText ();

				try
				{
					Scanner scan = new Scanner (new File ("password.txt"));
					String password = scan.next();

					if (enteredPW.equals(password))
						getAccessed = true;
					else
					{
						JOptionPane.showMessageDialog (null, "The password you input is worng. Try again, please");
						pwTF.setText("");
					}
				}	catch (IOException ioe)	 {	}
			}
		}
	}

	public void textfield_reset ()	{	pwTF.setText("");	}

	public boolean getGetAccessed ()	 {	return getAccessed;	 }
	public void resetGetAccessed ()	 {	getAccessed = false;	}
}